getApp();

var dataProvider = require("../../provider/dataApi.js"), pipe = require("../../provider/pipe.js"), wxParse = require("../../wxParse/article.js");

Page({
    data: {
        userId: "",
        statusBarHeight: "",
        titleBarHeight: "",
        wxshow: !1,
        userInfo: {},
        shareBtn: "",
        isshare: "",
        isloading: !0
    },
    onLoad: function(options) {
        this.setData({
            statusBarHeight: getApp().globalData.statusBarHeight,
            titleBarHeight: getApp().globalData.titleBarHeight
        }), console.log(options), options.parentId && this.btnShare(options.parentId);
    },
    goLogin: function() {
        wx.navigateTo({
            url: "../login/login"
        });
    },
    goVip: function() {
        wx.getStorageSync("uid") ? wx.navigateTo({
            url: "../vip/vip"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goMyExam: function() {
        wx.getStorageSync("uid") ? wx.navigateTo({
            url: "/pages/myExam/myExam"
        }) 
        : wx.navigateTo({
            url: "../login/login"
        });
    },
    goMedal: function() {
        wx.getStorageSync("uid") ? wx.navigateTo({
            url: "../my-medal/my-medal"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goInfo: function() {
        wx.getStorageSync("uid") ? wx.navigateTo({
            url: "../my-info/my-info"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goIntegralmall: function() {
        wx.getStorageSync("uid") ? wx.navigateTo({
            url: "../integral-mall/integral-mall"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goFeedback: function() {
        wx.getStorageSync("uid") ? wx.navigateTo({
            url: "../feedback/feedback"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goAbout: function() {
        this.setData({
            wxshow: !0
        });
    },
    confirmwx: function(event) {
        console.log(event.detail);
    },
    onClosewx: function() {
        this.setData({
            close: !1
        });
    },
    gosafeset: function() {
        wx.navigateTo({
            url: "../bindWechat/bindWechat"
        });
    },
    goSignout: function() {
        wx.showModal({
            title: "登出提示",
            content: "点击确定后将清空所有缓存,并退出到登录页,确定登出吗?",
            showCancel: !0,
            confirmText: "确定",
            success: function(response) {
                console.log(response), response.confirm && (wx.clearStorage(), wx.reLaunch({
                    url: "../login/login"
                }));
            }
        });
    },
    bindWechat: function() {
        wx.showModal({
            title: "绑定微信",
            content: "需要绑定微信才能进行下一步操作,点击确定去绑定",
            showCancel: !0,
            confirmText: "确定",
            success: function(response) {
                console.log(response), response.confirm && wx.navigateTo({
                    url: "../bindWechat/bindWechat"
                });
            }
        });
    },
    onShow: function() {
        this.setData({
            userId: wx.getStorageSync("uid")
        }), this.getuserinfo(), this.aboutus();
    },
    btnShare: function(parentId) {
        dataProvider.share({
            uid: parentId
        }).then(function(response) {
            console.log(response);
        }).catch(function(error) {
            console.log(error);
        });
    },
    onShareAppMessage: function(event) {
        return console.log(event), {
            title: "分享有礼",
            path: "/pages/mine/mine?parentId=" + this.data.userId
        };
    },
    getuserinfo: function() {
        var that = this;
        dataProvider.userinfo({
            uid: wx.getStorageSync("uid"),
            op: "getinfo"
        }).then(function(response) {
            console.log(response), wx.setStorageSync("userinfo", response.data.info), wx.setStorageSync("http", response.data.http), 
            that.setData({
                userInfo: response.data.info,
                isloading: !1
            });
        }).catch(function(error) {
            console.log(error), that.setData({
                isloading: !1
            });
        });
    },
    aboutus: function() {
        var that = this;
        dataProvider.aboutus({}).then(function(response) {
            console.log(response), null != response.data.about && (response.data.about = pipe.strcharacterDiscode(response.data.about).replace(/\<img/gi, '<img style="max-width:100px!important;height:auto"'), 
            wxParse.wxParse("article", "html", response.data.about, that, 5));
        }).catch(function(error) {
            console.log(error);
        });
    }
});